package com.ms.game.slot.base;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map.Entry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.game.common.GameType;
import com.ms.game.common.container.GainRateInfo;
import com.ms.game.common.container.GameOptionData;
import com.ms.game.itembox.ItemChangeParam;
import com.ms.game.slot.base.message.SGainRateData;
import com.ms.player.Player;
import com.xpec.c4.game.common.Helper;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.game.utility.WeightSelection;

/**
 * 增益系統(幣值比)
 */
public class GainRateSystem {
	
	private static final Log log = LogFactory.getLog(GainRateSystem.class);
	
	/**
	 * 系統預設的判斷gainRateID<br>
	 * 此ID的索引應該都是空的內容
	 */
	public static final int SYSTEM_DEFAULT_GAIN_RATE_ID = 0;
	
	/**
	 * 不參考此系統所使用的gainRateID
	 */
	public static final int EXCEPT_GAME_GAIN_RATE_ID = -1;
	
	/**
	 * 不參考GainRate的遊戲
	 */
	private static ArrayList<String> gainRateExceptGames = new ArrayList<String>();
	
	static{
	}
	
	/**
	 * server自己整理的設定資訊<br>
	 * key: gameType, hallType, gainRateID
	 */
	private static HashMap<String, HashMap<String, HashMap<Integer, GainRateData>>> gainRateMap;
	
	/**
	 * 增益類型對照MAP<br>
	 * key: gameType<br>
	 * key: hallType<br>
	 * key: gainRate<br>
	 * value: id
	 */
	private static HashMap<String, HashMap<String, HashMap<BigDecimal, Integer>>> gainTypeMap;
	
	/**
	 * 給client的資訊<br>
	 * key: gameType, hallType
	 */
	private static HashMap<String, HashMap<String, ArrayList<SGainRateData>>> toClientDatas;
	
	/**
	 * 假的client資訊<br>
	 * 為了提供那些不參考此系統的遊戲可以在介面上顯示的內容
	 */
	private static HashMap<String, HashMap<String, ArrayList<SGainRateData>>> fakeToClientDatas;
	
	/**
	 * 預設的增益類型ID<br>
	 * key: gameType<br>
	 * key: hallType
	 */
	private static HashMap<String, HashMap<String, Integer>> defaultGainRateID;
	
	/**
	 * {假的}預設的增益類型ID<br>
	 * key: gameType<br>
	 * key: hallType
	 */
	private static HashMap<String, HashMap<String, Integer>> fakeDefaultGainRateID;
	
	/**
	 * 是否是受此系統影響的遊戲
	 */
	public static boolean isAffectGame(String gameType){
		if(gameType == null || gainRateExceptGames.contains(gameType)){
			return false;
		}
		
		return true;
	}
	
	/**
	 * 從bin檔載入資訊
	 */
	public static void loadBinInfo(HashMap<String, HashMap<String, GameOptionData>> binHashMap){

		gainRateMap = new HashMap<String, HashMap<String,HashMap<Integer,GainRateData>>>();
		toClientDatas = new HashMap<String, HashMap<String,ArrayList<SGainRateData>>>();
		gainTypeMap = new HashMap<String, HashMap<String,HashMap<BigDecimal,Integer>>>();
		defaultGainRateID = new HashMap<String, HashMap<String,Integer>>();
		
		for(Entry<String, HashMap<String, GameOptionData>> entry : binHashMap.entrySet()){
			
			String gameType = entry.getKey();
			
			//不參考的遊戲，不處理
			if(!isAffectGame(gameType)){
				continue;
			}
			
			HashMap<String, HashMap<Integer,GainRateData>> gainRateDataMap = new HashMap<String, HashMap<Integer,GainRateData>>();
			HashMap<String, ArrayList<SGainRateData>> gainRateClient = new HashMap<String, ArrayList<SGainRateData>>();
			HashMap<String, HashMap<BigDecimal, Integer>> gainMap = new HashMap<String, HashMap<BigDecimal,Integer>>();
			HashMap<String, Integer> defaultGain = new HashMap<String, Integer>();
			for(Entry<String, GameOptionData> entry2 : entry.getValue().entrySet()){
				
				String hallType = entry2.getKey();
				GameOptionData optionData = entry2.getValue();
				
				HashMap<Integer,GainRateData> gainRateList = new HashMap<Integer,GainRateData>();
				ArrayList<SGainRateData> gainRateClientList = new ArrayList<SGainRateData>();
				HashMap<BigDecimal, Integer> gain = new HashMap<BigDecimal, Integer>();
				
				//檢查有沒有重複的ID或是比值
				ArrayList<Integer> gainRateIDCheck = new ArrayList<Integer>();
				ArrayList<BigDecimal> gainRateCheck = new ArrayList<BigDecimal>();
				
				for(Entry<String, GainRateInfo> entry3 : optionData.getMachineGainRate().entrySet()){
					
					String gainRateStr = entry3.getKey();
					GainRateInfo info = entry3.getValue();
					
					int id = info.getId();
					int limitLevel = info.getLimitLevel();
					int limitVIPLevel = info.getLimitVIPLevel();
					
					//檢查ID是否重複
					if(gainRateIDCheck.contains(id) || id == SYSTEM_DEFAULT_GAIN_RATE_ID){
						if(log.isErrorEnabled()){
							log.error("!!!duplicated gainRateID at "+gameType+"("+hallType+")");
						}
						continue;
					}
					else{
						gainRateIDCheck.add(id);
					}
					
					
					BigDecimal gainRate = getGainRateFromStringFormat(gainRateStr);
					if (gainRate == null) {
						if (log.isErrorEnabled()) {
							log.error("something wrong at parse gainRateStr to BigDecimal, str=" + gainRateStr);
						}
						continue;
					}
					else {
						//檢查比值是否重複
						if(gainRateCheck.contains(gainRate)){
							if (log.isErrorEnabled()) {
								log.error("!!!duplicated gainRate at " + gameType + "(" + hallType + 
										"), gainRate=" + gainRate + ", ID=" + id);
							}
							continue;
						}
						else{
							gainRateCheck.add(gainRate);
						}
					}
					
					GainRateData data = new GainRateData();
					data.setId(id);
					data.setBeginMachineID(info.getBeginMachineID());
					data.setEndMachineID(info.getEndMachineID());
					data.setGainRate(gainRate);
					data.setGainRateStringFormat(gainRateStr);
					data.setLimitLevel(limitLevel);
					data.setLimitVIPLevel(limitVIPLevel);
					data.setCanDoMission((info.getIsCanDoMission() >= 1));
					data.setOpen((info.getIsOpen() >= 1));
					
					// 加入小樂攜帶金錢的設定
					int robotLowestCarryMoney = info.getRobotLowestCarryMoney();
					HashMap<String, String> robotAddMoney = info.getRobotAddMoneyToken();
					if(robotLowestCarryMoney > 0 && robotAddMoney != null){
						WeightSelection<BigDecimal> weightSelection = new WeightSelection<BigDecimal>();
						for(Entry<String, String> robotMoneyEntry : robotAddMoney.entrySet()){
							String money = robotMoneyEntry.getKey();
							String token = robotMoneyEntry.getValue();
							try {
								int tokenInt = Integer.valueOf(token);
								if(tokenInt > 0){
									weightSelection.addWeightInfo(tokenInt, new BigDecimal(money));	
								}
							} catch (Exception e) {
								if(log.isErrorEnabled()){
									log.error("add robot add money token fail, money="+money+", token="+token);
								}
							}
						}
						data.setRobotLowestCarryMoney(new BigDecimal(robotLowestCarryMoney));
						data.setAddMoneySelect(weightSelection);
					}
					
					gainRateList.put(id, data);
					
					
					int[] gainRateForm = getGainRateForm(gainRateStr);
					SGainRateData clientData = new SGainRateData();
					clientData.setId(id);
					clientData.setGainRate(data.getGainRate().toString());
					clientData.setNumerator(gainRateForm[0]);
					clientData.setDenominator(gainRateForm[1]);
					clientData.setLimitLevel(limitLevel);
					clientData.setLimitVIPLevel(limitVIPLevel);
					clientData.setOpen(data.isOpen());
					gainRateClientList.add(clientData);
					
					gain.put(data.getGainRate(), id);
				}
				
				gainRateDataMap.put(hallType, gainRateList);
				gainRateClient.put(hallType, gainRateClientList);
				gainMap.put(hallType, gain);
				
				int defaultGainRateID = optionData.getDefaultGainRateID();
				if(defaultGainRateID == SYSTEM_DEFAULT_GAIN_RATE_ID){
					if(log.isWarnEnabled()){
						log.warn(gameType+"("+hallType+") using SYSTEM_DEFAULT_GAIN_RATE_ID may cause some error");
					}
				}
				
				defaultGain.put(hallType, optionData.getDefaultGainRateID());
			}
			
			gainRateMap.put(gameType, gainRateDataMap);
			toClientDatas.put(gameType, gainRateClient);
			gainTypeMap.put(gameType, gainMap);
			defaultGainRateID.put(gameType, defaultGain);
		}
		
		// 排序提供給client資訊的順序
		sortClientDatas();
		
		
		
		// 處理假的資訊，專門用來處理client表現上的資訊，不能拿來在正常的邏輯內使用
		fakeToClientDatas = new HashMap<String, HashMap<String, ArrayList<SGainRateData>>>();
		fakeDefaultGainRateID = new HashMap<String, HashMap<String,Integer>>();
		// 加入假資訊(這邊暫時先寫死，因為不知道企劃將來有沒有要實裝這些遊戲的比值系統
		String[] fakeGainRate = {"1:100", "1:1", "2:1", "5:1"};
		// 假的資訊理論上只會有一個是open，如果有多個可能會有問題
		boolean[] fakeOpen = {false, true, false, false};
		
		sortFakeClientDatas();
		
	}
	
	/**
	 * 排序提供給client的資訊
	 */
	private static void sortClientDatas(){
		if(toClientDatas == null){
			return;
		}
		
		for(HashMap<String, ArrayList<SGainRateData>> gainMapList : toClientDatas.values()){
			for(String hallType : gainMapList.keySet()){
				Collections.sort(gainMapList.get(hallType), new SGainRateDataComparator());
			}
		}
	}
	
	/**
	 * 加入假的幣值資訊給client
	 */
	private static void addFakeToClientDatas
	(
			String gameType,
			String hallType,
			String[] fakeGainRateStringFormat,
			boolean[] isOpens
	)
	{
		if(
				gameType == null ||
				hallType == null ||
				fakeGainRateStringFormat == null ||
				fakeGainRateStringFormat.length == 0
		)
		{
			return;
		}
		
		int defaultGainRateID = 0;
		ArrayList<SGainRateData> gainRateDatas = new ArrayList<SGainRateData>();
		for(int idx = 0; idx < fakeGainRateStringFormat.length; idx ++){
			String gainRateStr = fakeGainRateStringFormat[idx];
			BigDecimal gainRate = getGainRateFromStringFormat(gainRateStr);
			boolean isOpen = false;
			if(idx < isOpens.length){
				isOpen = isOpens[idx];
			}
			
			int gainRateID = idx + 1;
			
			if(gainRate != null){
				SGainRateData data = new SGainRateData();
				data.setId(gainRateID);
				data.setGainRate(gainRate.toString());
				data.setLimitLevel(0);
				data.setLimitVIPLevel(0);
				data.setOpen(isOpen);

				int[] gainRateForm = getGainRateForm(gainRateStr);
				data.setNumerator(gainRateForm[0]);
				data.setDenominator(gainRateForm[1]);

				gainRateDatas.add(data);
			}
			
			if(isOpen){
				defaultGainRateID = gainRateID;
			}
		}
		
		//假的比值資訊加入
		HashMap<String, ArrayList<SGainRateData>> fakeHallData = fakeToClientDatas.get(gameType);
		if(fakeHallData == null){
			fakeHallData = new HashMap<String, ArrayList<SGainRateData>>();
			fakeToClientDatas.put(gameType, fakeHallData);
		}
		fakeHallData.put(hallType, gainRateDatas);
		
		//假的預設gainRateID加入
		HashMap<String, Integer> fakeDefaultID = fakeDefaultGainRateID.get(gameType);
		if(fakeDefaultID == null){
			fakeDefaultID = new HashMap<String, Integer>();
			fakeDefaultGainRateID.put(gameType, fakeDefaultID);
		}
		fakeDefaultID.put(hallType, defaultGainRateID);
	}
	
	/**
	 * 排序{假的}提供給client的資訊
	 */
	private static void sortFakeClientDatas(){
		if(fakeToClientDatas == null){
			return;
		}
		
		for(HashMap<String, ArrayList<SGainRateData>> gainMapList : fakeToClientDatas.values()){
			for(String hallType : gainMapList.keySet()){
				Collections.sort(gainMapList.get(hallType), new SGainRateDataComparator());
			}
		}
	}
	
	/**
	 * 取得從字串型態取得增益<br>
	 * 例: 1:100 = 0.01, 1:1 = 1.00...(受限於Helper運算的小數精準位數)
	 */
	public static BigDecimal getGainRateFromStringFormat(String gainRateStringFormat){
		if(gainRateStringFormat == null){
			return null;
		}
		
		String[] rate = gainRateStringFormat.split(":");
		if(rate.length != 2){
			return null;
		}
		
		if(!GameUtility.isNumeric(rate[0]) || ! GameUtility.isNumeric(rate[1])){
			return null;
		}
		
		return Helper.div(new BigDecimal(rate[0]), new BigDecimal(rate[1]));
	}
	
	/**
	 * 取得增益的分子分母型態
	 */
	public static int[] getGainRateForm(String gainRateStringFormat){
		if(gainRateStringFormat == null){
			return null;
		}
		
		String[] rate = gainRateStringFormat.split(":");
		if(rate.length != 2){
			return null;
		}
		
		if(!GameUtility.isNumeric(rate[0]) || ! GameUtility.isNumeric(rate[1])){
			return null;
		}
		
		int[] result = new int[2];
		result[0] = Integer.valueOf(rate[0]);
		result[1] = Integer.valueOf(rate[1]);
		return result;
	}
	
	/**
	 * 取得該遊戲館，該gainRate資訊
	 */
	public static GainRateData getGainRateData(String gameType, String hallType, BigDecimal gainRate){
		int gainRateID = getGainRateID(gameType, hallType, gainRate);
		return getGainRateData(gameType, hallType, gainRateID);
	}
	
	/**
	 * 取得該遊戲館，該gainRateID資訊
	 */
	public static GainRateData getGainRateData(String gameType, String hallType, int gainRateID){
		HashMap<String, HashMap<Integer,GainRateData>> gainRate = gainRateMap.get(gameType);
		if(gainRate != null && gainRate.containsKey(hallType)){
			return gainRate.get(hallType).get(gainRateID);
		}
		
		return null;
	}
	
	/**
	 * 取得該遊戲的機台設定
	 */
	public static ArrayList<GainRateData> getGainRateList(String gameType, String hallType){
		if(gameType == null || hallType == null){
			return null;
		}
		
		HashMap<String, HashMap<Integer,GainRateData>> gainRate = gainRateMap.get(gameType);
		if(gainRate != null && gainRate.containsKey(hallType)){
			return new ArrayList<GainRateData>(gainRate.get(hallType).values());
		}
		
		return null;
	}
	
	/**
	 * 取得該遊戲的增益比ID
	 */
	public static int getGainRateID(String gameType, String hallType, BigDecimal gainRate){
		if(gameType == null || hallType == null || gainRate == null){
			return SYSTEM_DEFAULT_GAIN_RATE_ID;
		}
		
		HashMap<String, HashMap<BigDecimal, Integer>> gainMap = gainTypeMap.get(gameType);
		if(gainMap == null){
			return SYSTEM_DEFAULT_GAIN_RATE_ID;
		}
		
		HashMap<BigDecimal, Integer> gainTypeMap = gainMap.get(hallType);
		if(gainTypeMap == null){
			return SYSTEM_DEFAULT_GAIN_RATE_ID;
		}
		
		return gainTypeMap.get(gainRate);
	}
	
	/**
	 * 取得該遊戲館的預設gainRateID
	 */
	public static int getDefaultGainRateID(String gameType, String hallType){
		HashMap<String, Integer> defaultGain = defaultGainRateID.get(gameType);
		if(defaultGain != null && defaultGain.containsKey(hallType)){
			return defaultGain.get(hallType);
		}
		
		return SYSTEM_DEFAULT_GAIN_RATE_ID;
	}
	
	/**
	 * 取得遊戲館的設定(toClient)
	 */
	public static ArrayList<SGainRateData> getGainRateDatas(String gameType, String hallType){
		HashMap<String, ArrayList<SGainRateData>> clientDatas = toClientDatas.get(gameType);
		if(clientDatas != null && clientDatas.containsKey(hallType)){
			return clientDatas.get(hallType);
		}
		
		return null;
	}
	
	/**
	 * 取得{假的}該遊戲館的預設gainRateID
	 */
	public static int getFakeDefaultGainRateID(String gameType, String hallType){
		HashMap<String, Integer> defaultGain = fakeDefaultGainRateID.get(gameType);
		if(defaultGain != null && defaultGain.containsKey(hallType)){
			return defaultGain.get(hallType);
		}
		
		return SYSTEM_DEFAULT_GAIN_RATE_ID;
	}
	
	/**
	 * 取得{假的}遊戲館的設定(toClient)
	 */
	public static ArrayList<SGainRateData> getFakeGainRateDatas(String gameType, String hallType){
		HashMap<String, ArrayList<SGainRateData>> clientDatas = fakeToClientDatas.get(gameType);
		if(clientDatas != null && clientDatas.containsKey(hallType)){
			return clientDatas.get(hallType);
		}
		
		return null;
	}
	
	/**
	 * 玩家是否能在該比值遊玩
	 */
	public static boolean isPlayerCanPlay
	(
			int level,
			int VIPLevel,
			String gameType,
			String hallType,
			int gainRateID,
			boolean isAskingForMachineList
	)
	{
		if (gameType == null || hallType == null) {
			return false;
		}

		// 不在這個系統的遊戲
		if (gainRateExceptGames.contains(gameType)) {
			return true;
		}

		// 使用預設ID
		if (gainRateID == SYSTEM_DEFAULT_GAIN_RATE_ID) {
			// 允許是要來查詢預設機台列表的
			if (isAskingForMachineList) {
				return true;
			}
			// 其他情況都不允許
			else {
				return false;
			}
		}

		GainRateData gainRateData = getGainRateData(gameType, hallType, gainRateID);
		if (gainRateData != null) {
			
			// 未開放不能玩
			if(!gainRateData.isOpen()){
				return false;
			}

			int limitLevel = gainRateData.getLimitLevel();
			int limitVIPLevel = gainRateData.getLimitVIPLevel();

			// 有等級限制，沒有VIP等級限制
			if (limitLevel > 0 && limitVIPLevel <= 0) {
				if (level >= limitLevel) {
					return true;
				}
			}
			// 沒有等級限制，有VIP等級限制
			else if (limitLevel <= 0 && limitVIPLevel > 0) {
				if (VIPLevel >= limitVIPLevel) {
					return true;
				}
			}
			// 有等級與VIP等級限制
			else if (limitLevel > 0 && limitVIPLevel > 0) {
				// 其中一項達成即可
				if (level >= limitLevel || VIPLevel >= limitVIPLevel) {
					return true;
				}
			}
			// 都沒有限制
			else if (limitLevel <= 0 && limitVIPLevel <= 0) {
				return true;
			}

		}

		return false;
	}
	
	/**
	 * 玩家實際的下注額是否足夠
	 */
	public static boolean isPlayerMoneyEnough
	(
			Player player,
			int totalBetMoney,
			BigDecimal gainRate
	)
	{
		if(player == null){
			return false;
		}
		
		BigDecimal playerCoin = (player.isUseTrialCoin()) ? player.getTrialCoin() : player.getGoldCoin();
		BigDecimal orgTotalBet = new BigDecimal(totalBetMoney);
		
		//增益為怪異的值
		if(gainRate == null || Helper.isMinus(gainRate)){
			return Helper.isGreaterEqual(playerCoin, orgTotalBet);
		}
		else{
			BigDecimal reaTotallBet = Helper.mul(orgTotalBet, gainRate);
			return Helper.isGreaterEqual(playerCoin, reaTotallBet);
		}
	}
	
	/**
	 * 取得真實金錢
	 */
	public static BigDecimal getRealMoney(long money, BigDecimal gainRate){
		if(money <= 0 || gainRate == null){
			return BigDecimal.ZERO;
		}
		
		return Helper.mul(new BigDecimal(money), gainRate);
	}
	
	/**
	 * 取得真實金錢
	 */
	public static BigDecimal getRealMoney(BigDecimal money, BigDecimal gainRate){
		if(money == null || gainRate == null || Helper.isLessEqual(money, BigDecimal.ZERO)){
			return BigDecimal.ZERO;
		}
		
		return Helper.mul(money, gainRate);
	}
	
	/**
	 * 是否可以進行任務(gainRate)
	 */
	public static boolean isCanDoMission(String gameType, String hallType, BigDecimal gainRate){
		int gainRateID = getGainRateID(gameType, hallType, gainRate);
		return isCanDoMission(gameType, hallType, gainRateID);
	}
	
	/**
	 * 是否可以進行任務(gainRateID)
	 */
	public static boolean isCanDoMission(String gameType, String hallType, int gainRateID){
		if(gameType == null || hallType == null){
			return false;
		}
		
		// 不受影響的遊戲，允許執行
		if(gainRateExceptGames.contains(gameType)){
			return true;
		}
		
		GainRateData gainRateData = getGainRateData(gameType, hallType, gainRateID);
		// 開放且可以執行任務的比值
		if(gainRateData != null && gainRateData.isOpen() && gainRateData.isCanDoMission()){
			return true;	
		}
			
		return false;
	}
	
	/**
	 * 是否可以進行任務(道具變化資訊)
	 */
	public static boolean isCanDoMission(ItemChangeParam itemChangeParam){
		if(itemChangeParam == null){
			return false;
		}
		
		String gameType = itemChangeParam.getGameHallId();
		String hallType = itemChangeParam.getGameHallName();
		
		//是否是在遊戲中使用
		boolean isUseInGame = false;
		try {
			GameType gType = GameType.valueOf(gameType);
			if(gType != null){
				isUseInGame = true;
			}
		} catch (Exception e) {
			
		}
		
		//不受幣值影響的遊戲全部都可以
		if(!isUseInGame || !isAffectGame(gameType)){
			return true;
		}
		
		return isCanDoMission(gameType, hallType, itemChangeParam.getGainRate());
	}
	
	
	
	/**
	 * SGainRateData的排序方式<br>
	 * 優先權：ID小到大、gainRate小到大
	 */
	private static class SGainRateDataComparator implements Comparator<SGainRateData> {
		@Override
		public int compare(SGainRateData o1, SGainRateData o2) {
			if (o1.getId() > o2.getId()) {
				return 1;
			} else if (o1.getId() < o2.getId()) {
				return -1;
			} else if (o1.getId() == o2.getId()) { // ID一樣，比較倍率

				BigDecimal gainRateO1 = new BigDecimal(o1.getGainRate());
				BigDecimal gainRateO2 = new BigDecimal(o2.getGainRate());
				
				if (Helper.isGreater(gainRateO1, gainRateO2)) {
					return 1;
				} else if (Helper.isLess(gainRateO1, gainRateO2)) {
					return -1;
				}
			}
			return 0;
		}
	}
	
	/**
	 * 取得假的玩家分佈情形(在統計無法正確分辨比值玩家時暫時的處理方式)
	 */
//	public static int getFakePlayerInSeatCount(String gameType, String hallType, int gainRateID, int count){
//		if(count <= 0){
//			return 0;
//		}
//		
//		// 如果是受幣值影響的遊戲
//		if(isAffectGame(gameType)){
//			
//			//先暫時以玩家按照座位比例入座的假人數去處理
//			//要等統計那邊做好比值人數的正確數字再修正
//			ArrayList<GainRateData> gainRateDatas = getGainRateList(gameType, hallType);
//			if(gainRateDatas == null){
//				return count;
//			}
//			
//			int currentToken = 0;
//			int maxToken = 0;
//			for(GainRateData gainRateData : gainRateDatas){
//				int seatCount = gainRateData.getEndMachineID() - gainRateData.getBeginMachineID() + 1;
//				if(gainRateData.getId() == gainRateID){
//					currentToken = seatCount;
//				}
//				
//				maxToken += seatCount;
//			}
//			
//			if(currentToken <= 0 || maxToken <= 0){
//				return 0;
//			}
//			else{
//				//此比值的總座位占比
//				BigDecimal rate = Helper.div(currentToken, maxToken);
//				//依照占比算出假的分佈人數
//				return Helper.mul(new BigDecimal(count), rate).intValue();
//			}
//		}
//		
//		else return count;
//	}
	
}
